#!/bin/sh

BASEPATH=$(cd `dirname $0`; pwd)

TARGET_DIR="/usr/local/vhs"

systemctl stop vhs.service

# copy files
mkdir -p $TARGET_DIR

if [ -f $TARGET_DIR/vhs.s3db ]; then
	mkdir -p $TARGET_DIR/bak
	cp $TARGET_DIR/vhs.s3db $TARGET_DIR/bak/
	cp $TARGET_DIR/vhs.ini $TARGET_DIR/bak/
	
	cp -rf * /usr/local/vhs/
	
	cp $TARGET_DIR/bak/vhs.s3db $TARGET_DIR/
	cp $TARGET_DIR/bak/vhs.ini $TARGET_DIR/
	
else
	cp -rf * /usr/local/vhs/
fi

chmod a+wx $TARGET_DIR -R

mkdir -p /usr/lib/systemd/system/
cp $TARGET_DIR/vhs.service /usr/lib/systemd/system/vhs.service

systemctl enable vhs.service

systemctl start vhs.service